var xmlhttp;

function getXmlHttpObject()
{
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return xmlhttp;
}

function pushMessage(type)
{
	
	getXmlHttpObject();
	var message;
	if(type == 0){

		message = document.getElementById("allMessage").value;
	}
	else if(type == 1){
		message = document.getElementById("ibtMessage").value;
	}
	else if(type == 2){

		message = document.getElementById("gmatMessage").value;
	}
	else if(type == 3){

		message = document.getElementById("greMessage").value;
	}
	window.location="../controllers/pushNotification.php?"+"message=" + message + "&type=" + type;
	
}

function pushMessageSuccess() {
	if (xmlhttp.readyState == 4)
		if (xmlhttp.status == 200)
		{	
			alert("推送成功！");
		}
	    else if (request.status == 404)
	        alert("请求的链接不存在");
	    else
	        alert("错误: 错误代码 " + xmlhttp.status);
}


function savePushMessage(type)
{
	
	getXmlHttpObject();
	var message;
	if(type == 0){

		message = document.getElementById("allMessage").value;
	}
	else if(type == 1){
		message = document.getElementById("ibtMessage").value;
	}
	else if(type == 2){

		message = document.getElementById("gmatMessage").value;
	}
	else if(type == 3){

		message = document.getElementById("greMessage").value;
	}
	var url = "../controllers/savePushNotification.php";
	var params = "message=" + message + "&type=" + type; 
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = savePushMessageSuccess;
	xmlhttp.send(params);
	
}

function savePushMessageSuccess() {
	if (xmlhttp.readyState == 4)
		if (xmlhttp.status == 200)
		{	
			alert("保存推送成功！");
			window.location.reload();
		}
	    else if (request.status == 404)
	        alert("请求的链接不存在");
	    else
	        alert("错误: 错误代码 " + xmlhttp.status);
}